home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- ============================================================
- Example for sorting dates in the ISO format yyyy-mm-dd
- Use with: Dates0.xml
- Notes:-
- 1) The hyphen separator is optional
- ================================================================= -->
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
- <!-- define variable that is used as the separator in dates -->
- <!-- (this saves having to re-work the code for different separators -->
- <xsl:variable name="date-sep" select="'/'"/>
- <xsl:template match="/">
- <html><body>
- <table border="1">
- <tr>
- <th>Sorted Position</th>
- <th>Sort value</th>
- <th>Original date value</th>
- <th>Original position</th>
- </tr>
- <xsl:for-each select="/root/item">
- <!-- sort algorithm -->
- <xsl:sort select="translate(@date,'-','')" data-type="number"/>
- <tr>
- <td>
- <xsl:value-of select="position()"/>
- </td>
- <td>
- <!-- the numeric date -->
- <xsl:value-of select="translate(@date,'-','')"/>
- </td>
- <td>
- <xsl:value-of select="@date"/>
- </td>
- <td>
- <!-- show the order of the element in the original xml -->
- <xsl:value-of select="count(preceding-sibling::item)+1"/>
- </td>
- </tr>
- </xsl:for-each>
- </table>
- </body></html>
- </xsl:template>
- </xsl:stylesheet>